<?php

namespace Home\Controller;

use Think\Controller;

class FinanceController extends BaseController
{

    /**
     * 页面显示
     */
    public function index()
    {
        //用户id
        $user_id = $this->user_info['id'];

        //获取锁仓数量
//        $lockData = M('locked')->where(['userid'=>$user_id,'status'=>0])->sum('amount');
        //获取账户信息
        $userData = M('user')->where(['id' => $user_id])->find();

        $rate = $this->finance_rate();//美元兑换人民币价格
//        $userData['z1_cny'] = $userData['z1'] * $rate;
        $config=M('reward_config')->find();
        $userData['total_money'] = $userData['z7']*$config['asset_price']+$userData['z8'];
        $this->assign('userData', $userData);
        $this->display();
    }
    /**
     * 佣金提现
     * User: ming
     * Date: 2019/7/24 10:17
     */
    public function commission()
    {
        //用户id
        $user_id = $this->user_info['id'];
        //获取账户信息
        $userData = M('user')->where(['id' => $user_id])->find();
        //获取手续费参数
        $configData = M('reward_config')->find();
        //asset实时价格
        $coin_asset = $this->asset_price();
        //easy实时价格
        $coin_easy = $this->easy_price();

        if (IS_POST) {
            //接收参数
            $data = I('post.');
//            if ($userData['is_real'] != 2) {
//                $this->ajaxReturn(array('code' => '-1', 'message' => '请先到个人中心完成实名认证'));
//            }
            if ($data['amount'] == '' || $data['amount'] <= 0) {
                $this->ajaxReturn(array('code' => '-1', 'message' => '信息不完整'));
            }
            //最低限额
            if ($data['amount'] < $configData['p43']) {
                $this->ajaxReturn(array('code' => '-1', 'message' => '低于' . $configData['p43'] . '不能兑换'));
            }
            $coinFrom = "z" . $data['from'];//币名
            if ($data['amount'] > $userData['z6']) {
                $this->ajaxReturn(array('code' => '-1', 'message' => '账户余额不足'));
            }

            $finance_rate = $this->finance_rate();//美元兑换人民币价格
            $usdt_price = round($data['amount'] / $finance_rate, 4);//人民币兑换usdt
            $param['amount'] = 0;//默认值
//            if ($data['from'] == 8) {
//                $param['amount'] = $usdt_price;  //usdt
//            } else
            if ($data['from'] == 7) {
                $param['amount'] = round($usdt_price / $coin_asset, 4);//asset价格
            } elseif ($data['from'] == 11) {
                $param['amount'] = round($usdt_price / $coin_easy, 4);//easy价格
            }

            //减去账户余额
            $res1 = M('user')->where(['id' => $user_id])->setDec('z6', $data['amount']);
            $res2 = M('user')->where(['id' => $user_id])->setInc($coinFrom, $param['amount']);//asset存币总额
            $res3 = $this->add_log($user_id, $user_id, -$param['amount'], $data['from'], '佣金提取', "60" . $data['from']);
            if ($res1 && $res2 && $res3) {
                $this->ajaxReturn(array('code' => '1', 'message' => '提取成功'));
            } else {
                $this->ajaxReturn(array('code' => '-1', 'message' => '提取失败'));
            }
        } else {

            $this->assign('coin_asset', $coin_asset);
            $this->assign('coin_easy', $coin_easy);
            $this->assign('configData', $configData);
            $this->assign('userData', $userData);

            $this->display();
        }
    }

        /**
         * 复投
         * User: ming
         * Date: 2019/10/30 15:13
         */
        public function redelivery(){
            //用户id
            $user_id = $this->user_info['id'];
            //获取账户信息
            $userData = M('user')->where(['id' => $user_id])->find();
            $config = M('reward_config')->find();
            if (IS_POST) {
//                if ($userData['is_real'] != 2) {
//                    $this->ajaxReturn(array('code' => '-1', 'message' => '请先到个人中心完成实名认证'));
////                ajax_return(1, '请先到个人中心完成实名认证');
//                }
                //接收数据
                $data = I('post.');

                //判断是否为空
                if ($data['password2'] == ''||$data['amount'] == ''||$data['amount']<=0) {
                    $this->ajaxReturn(array('code' => '-1', 'message' => '请输入完整的信息'));
                }
                if ($userData['password2'] != MD5($data['password2'])) {
                    $this->ajaxReturn(array('code' => '-1', 'message' => '请输入正确的支付密码'));
                }

                $charge = $data['amount'] * $config['j1'];//手续费
//                $price=$data['amount']+$charge;
//                //判断账户余额是否足够
//                if ($price > $userData['z9']) {
//                    $this->ajaxReturn(array('code' => '-1', 'message' => '账户余额不足,手续费'.$charge));
//                }
                if ($data['amount'] > $userData['z9']) {
                    $this->ajaxReturn(array('code' => '-1', 'message' => '账户余额不足'));
                }
                $res1 = $this->add_log($user_id, $user_id, $data['amount'], 9, "信托", 903, $charge);
                //减去账户余额
                $res2 = M('user')->where(['id' => $user_id])->setDec('z9', $data['amount']);

                $asset_price=$this->asset_price();//实时价格
                $money= $data['amount']-$charge;//ASSET
                $param['amount'] = $money*$asset_price;//usdt

//                //收益范围20191105
//                if ($param['amount'] < $config['p6']) {
//                    $this->ajaxReturn(array('code' => '-1', 'message' => '不能小于存币生息最小范围' . $config['p6']));
//                }
//                //静态收益等级A20191030
//                if ($config['p6'] <= $param['amount'] && $param['amount'] <= $config['p7']) {
//                    $param['type'] = 1;//A1
//                }
//                if ($config['p8'] <= $param['amount'] && $param['amount'] <= $config['p9']) {
//                    $param['type'] = 2;//A2
//                }
//                if ($param['amount'] >= $config['p10']) {
//                    $param['type'] = 3;//A3
//                }

                $param['userid'] = $user_id;

                $param['addtime'] = time();
                $param['coin_type'] = 7;//币种20190801
                $param['is_class'] = 2;//信托分类
                $param['coin_price'] = $money;//ASSET
                $res3 = M('locked')->add($param);//存币生息
                if ($res1 && $res2 &&$res3) {
                    $db = M();
                    $money = $param['amount'];//USDT
//                20191107统一生息成ASSET
                    $db->execute("call kt002($user_id,$money)");

                    $this->ajaxReturn(array('code' => '1', 'message' => '复投成功'));
                } else {
                    $this->ajaxReturn(array('code' => '-1', 'message' => '失败'));
                }
            } else {
//                $rate = $this->finance_rate();//美元兑换人民币价格
//                $userData['z1_cny'] = $userData['z1'] * $rate;
                $this->assign('userData', $userData);

                //获取存币生息利润提现记录
                $where['user_id'] = $user_id;
                $where['type'] = 9;//复投
                $where['reward_type'] = 903;
                $count = M('fmoney')->where($where)->count();
                $Page = new \Think\Page($count, 4);
//            $Page->setConfig(prev, '上一页');
//            $Page->setConfig(next, '下一页');
                $show = $Page->show();
                $data = M('fmoney')->where($where)->limit($Page->firstRow . ',' . $Page->listRows)->order('id desc')->select();

                $price['all_price'] = M('fmoney')->where($where)->sum('amount');
                //获得当日凌晨的时间戳
                $today = strtotime(date("Y-m-d"),time());
                $where['create_time']=['gt',$today];
                $price['today_price'] = M('fmoney')->where($where)->sum('amount');
                $this->assign('price', $price);

                $this->assign('chargeData', $data);
                $this->assign('page', $show);

                $this->assign('config', $config);
                $this->display();
            }
        }
    /**
     * 存币生息利润提现成ASSET
     * User: ming
     * Date: 2019/7/24 10:35
     */
    public function profit()
    {
        //用户id
        $user_id = $this->user_info['id'];
        //获取账户信息
        $userData = M('user')->where(['id' => $user_id])->find();
        $config = M('reward_config')->find();
        if (IS_POST) {
//            if ($userData['is_real'] != 2) {
//                $this->ajaxReturn(array('code' => '-1', 'message' => '请先到个人中心完成实名认证'));
////                ajax_return(1, '请先到个人中心完成实名认证');
//            }

            //接收数据
            $data = I('post.');
            //判断是否为空
            if ($data['amount'] == ''||$data['password2']=='') {
                $this->ajaxReturn(array('code' => '-1', 'message' => '信息不能为空'));
            }
            if ($userData['password2'] != MD5($data['password2'])) {
                $this->ajaxReturn(array('code' => '-1', 'message' => '请输入正确的支付密码'));
            }
            //判断账户余额是否足够
            if ($data['amount'] > $userData['z9']) {
                $this->ajaxReturn(array('code' => '-1', 'message' => '账户余额不足'));
            }
            $charge = $data['amount'] * $config['p41'];//手续费
            $res1 = $this->add_log($user_id, $user_id, -($data['amount']), 9, "存币生息收益提取", 901, $charge);
            //减去账户余额
            $res2 = M('user')->where(['id' => $user_id])->setDec('z9', $data['amount']);
            $balance = $data['amount'] - $charge;//减去手续费到账ASSET

            $res3 = M('user')->where(['id' => $user_id])->setInc('z7', $balance);
            $res4 = $this->add_log($user_id, $user_id, $balance, 7, "存币生息收益提取", 711, $charge);
            if ($res1 && $res2 && $res3 && $res4) {
                $this->ajaxReturn(array('code' => '1', 'message' => '提取成功'));
            } else {
                $this->ajaxReturn(array('code' => '-1', 'message' => '提取失败'));
            }
        } else {
            $rate = $this->finance_rate();//美元兑换人民币价格
            $userData['z1_cny'] = $userData['z1'] * $rate;
            $this->assign('userData', $userData);

            //获取存币生息利润提现记录
            $where['user_id'] = $user_id;
            $where['type'] = 9;//存币生息ASSET收益
            $where['reward_type'] = 901;
            $count = M('fmoney')->where($where)->count();
            $Page = new \Think\Page($count, 4);
//            $Page->setConfig(prev, '上一页');
//            $Page->setConfig(next, '下一页');
            $show = $Page->show();
            $data = M('fmoney')->where($where)->limit($Page->firstRow . ',' . $Page->listRows)->order('id desc')->select();
            $this->assign('chargeData', $data);
            $this->assign('page', $show);

            $this->assign('config', $config);
            $this->display();
        }

    }

    /**
     * 存币生息利润提现成EASY
     * User: ming
     * Date: 2019/8/2 10:35
     */
    public function profit2()
    {
        //用户id
        $user_id = $this->user_info['id'];
        //获取账户信息
        $userData = M('user')->where(['id' => $user_id])->find();
        $config = M('reward_config')->find();
        if (IS_POST) {
//            if ($userData['is_real'] != 2) {
//                $this->ajaxReturn(array('code' => '-1', 'message' => '请先到个人中心完成实名认证'));
////                ajax_return(1, '请先到个人中心完成实名认证');
//            }

            //接收数据
            $data = I('post.');
            //判断是否为空
            if ($data['amount'] == '') {
                $this->ajaxReturn(array('code' => '-1', 'message' => '数量不能为空'));
            }
            //判断账户余额是否足够
            if ($data['amount'] > $userData['z12']) {
                $this->ajaxReturn(array('code' => '-1', 'message' => '账户余额不足'));
            }
            $charge = $data['amount'] * $config['p41'];//手续费
            $res1 = $this->add_log($user_id, $user_id, -($data['amount']), 12, "存EASY币生息收益提取", 1201, $charge);
            //减去账户余额
            $res2 = M('user')->where(['id' => $user_id])->setDec('z12', $data['amount']);
            $balance = $data['amount'] - $charge;//减去手续费到账ASSET

            $res3 = M('user')->where(['id' => $user_id])->setInc('z11', $balance);
            $res4 = $this->add_log($user_id, $user_id, $balance, 11, "存EASY币生息收益提取", 1111, $charge);
            if ($res1 && $res2 && $res3 && $res4) {
                $this->ajaxReturn(array('code' => '1', 'message' => '提取成功'));
            } else {
                $this->ajaxReturn(array('code' => '-1', 'message' => '提取失败'));
            }
        } else {
//            $rate = $this->finance_rate();//美元兑换人民币价格
//            $userData['z1_cny'] = $userData['z1'] * $rate;
            $this->assign('userData', $userData);

            //获取存币生息利润提现记录
            $where['user_id'] = $user_id;
            $where['type'] = 12;//存币生息ASSET收益
            $where['reward_type'] = 1201;
            $count = M('fmoney')->where($where)->count();
            $Page = new \Think\Page($count, 4);
//            $Page->setConfig(prev, '上一页');
//            $Page->setConfig(next, '下一页');
            $show = $Page->show();
            $data = M('fmoney')->where($where)->limit($Page->firstRow . ',' . $Page->listRows)->order('id desc')->select();
            $this->assign('chargeData', $data);
            $this->assign('page', $show);

            $this->assign('config', $config);
            $this->display();
        }

    }

    /**
     * 充提币页面
     * User: ming
     * Date: 2019/7/22 9:30
     */
    public function wallet()
    {
        //用户id
        $user_id = $this->user_info['id'];

        //获取锁仓数量
//        $lockData = M('locked')->where(['userid'=>$user_id,'status'=>0])->sum('amount');
        //获取账户信息
        $userData = M('user')->where(['id' => $user_id])->find();
        $this->assign('userData', $userData);


        //获取余额记录
        $where['userid'] = $user_id;
//        $where['reason'] = '余额分红';
        $count = M('coinlist')->where($where)->count();
        $Page = new \Think\Page($count, 5);
        $Page->setConfig(prev, '上一页');
        $Page->setConfig(next, '下一页');
        $show = $Page->show();
        $data = M('coinlist')->where($where)->limit($Page->firstRow . ',' . $Page->listRows)->order('id desc')->select();

        $this->assign('chargeData', $data);
        $this->assign('page', $show);

//        $this->getBTC();
//        $this->getEth();

        $this->getEASY();
        $this->getUSDT();
        $this->getWFX();

        $this->display();
    }

    //获取币种名称
    public function coinName()
    {
        $data = I('post.');

        $userid = $this->user_info['id'];
        $userData = M('user')->where(['id' => $userid])->find();

        if ($data['coinname'] == 1) {
            ajax_return(0, 'BTC', $userData['btc_address']);

        } elseif ($data['coinname'] == 2) {

            ajax_return(0, 'ETH', $userData['eth_address']);

        } elseif ($data['coinname'] == 3) {

            ajax_return(0, 'USDT', $userData['eth_address']);
//            ajax_return(0,'USDT',$userData['usdt_address']);


        } elseif ($data['coinname'] == 4) {

//            ajax_return(0,'WFX',$userData['eth_address']);
            ajax_return(0, 'ASSET', $userData['eth_address']);

        } elseif ($data['coinname'] == 5) {
            ajax_return(0, 'EASY', $userData['eth_address']);
        }else{
            ajax_return(0, 'COIN', $userData['eth_address']);
        }

//        if($data['coinname'] == 1)
//        {
//            $qrcode == 1;
//        }else
//        {
//            $qrcode == 2;
//        }
//
//        $this->assign('qrcode',$qrcode);
//
//        $this->assign('coinAddress', $coinAddress);

    }

    //生成ETH地址
    public function ethAddress()
    {
        $data = I('post.');

        //判断地址是否存在
        $userid = $this->user_info['id'];

        $userData = M('user')->where(['id' => $userid])->find();

        if (!empty($userData['eth_address'])) {
            ajax_return(1, '请勿重复申请');
        }
//        $coinArr=$this->auto_coin();//随机平台钱包地址
//        $info['usdt_address'] = $coinArr['from'];
        $info['eth_address'] = $data['address'];
        $info['eth_key'] = $data['key'];
        $info['coin_time'] = time();
        $info['is_address'] = 2;


        $res = M('user')->where(['id' => $userid])->save($info);

        if ($res) {
            ajax_return(0, '申请成功');
        } else {
            ajax_return(1, '申请失败');
        }
        //ajax_return(0,'申请成功');
        //ajax_return(1,'申请失败');

    }


    /**
     * 充值页面
     */
    public function charge()
    {
        if (IS_POST) {
            $data = I('post.');

            //判断充币信息是否完整
            if ($data['address'] == '' || $data['amount'] == '') {
                $this->ajaxReturn(array('code' => '-1', 'message' => '充币信息不完整'));
            }

            //判断充值数量是否为0
            if ($data['amount'] <= 0) {
                $this->ajaxReturn(array('code' => '-1', 'message' => '充值数量不能为0'));
            }

            //用户id
            $user_id = $this->user_info['id'];

            //数据入库

            $data['userid'] = $user_id;
            $data['addtime'] = time();
            $data['status'] = 0;

            $res = M('charge')->add($data);

            if ($res) {
                $this->ajaxReturn(array('code' => '1', 'message' => '申请成功'));
            } else {
                $this->ajaxReturn(array('code' => '-1', 'message' => '申请失败'));
            }


        } else {
            //用户id
            $user_id = $this->user_info['id'];

            //获取BTC信息
//			$addressData = M('address')->where(['userid'=>$user_id])->find();
//			$this->assign('addressData', $addressData);

            //判断是否生成钱包地址
//            $userid = $this->user_info['id'];
            $userData = M('user')->where(['id' => $user_id])->find();

            $this->assign('isAddress', $userData['is_address']);

            $this->assign('coinAddress', $userData['eth_address']);
            $this->display();
        }
    }


    /**
     * 申请明细
     */
    public function detail()
    {
        //用户id
        $user_id = $this->user_info['id'];

        //获取锁仓记录
        $where['userid'] = $user_id;
        $count = M('charge')->where($where)->count();
        $Page = new \Think\Page($count, 8);
        $Page->setConfig(prev, '上一页');
        $Page->setConfig(next, '下一页');
        $show = $Page->show();
        $data = M('charge')->where($where)->limit($Page->firstRow . ',' . $Page->listRows)->order('id desc')->select();
        $this->assign('detailData', $data);
        $this->assign('page', $show);

        $this->display();
    }


    /**
     * 提币页面
     */
    public function withdraw()
    {
        $userid = $this->user_info['id'];
        $userData = M('user')->where(['id' => $userid])->find();
        $config = M('reward_config')->find();
        if (IS_POST) {
//            if ($userData['is_real'] != 2) {
////                $this->ajaxReturn(array('code'=>'-1','message'=>'请先到个人中心完成实名认证'));
//                ajax_return(1, '请先到个人中心完成实名认证');
//            }

            $data = I('post.');
            //验证信息是否完整
//            if($data['coinname'] == '' || $data['address'] == '' || $data['amount'] == '' || $data['password'] == '')
            if ($data['coinname'] == '' || $data['address'] == '' || $data['amount'] == '' || $data['password'] == '' || $data['phone'] == '' || $data['getCode'] == '') {
                //ajax_return(0,'申请成功');
                ajax_return(1, '提币信息不完整');
            }
            //短信
            $code['mobile'] = $data['phone'];
            $code['code'] = $data['getCode'];
            if (!M('msg_list')->where($code)->order('id desc')->find()) {
                ajax_return(1, '验证码不正确');
            }

            //验证支付密码
            if (md5($data['password']) != $userData['password2']) {
//            if (md5($data['password']) != $userData['password']) {
                ajax_return(1, '支付密码错误');
            }

            //判断余额是足够
            if ($data['amount'] <= 0) {
                ajax_return(1, '提币数量不能小于等于0');
            }

            $amount = 0;//总共扣除币默认为0
            $charge = 0;//手续费默认为0
            if ($data['coinname'] == 1) {
                //BTC2019052117
                if ($config['ptr77'] > $data['amount']) {
                    ajax_return(1, '超过最低限额' . $config['ptr77']);
                }
                //手续费扣除
                $charge = $data['amount'] * $config['ptr73'];
                $amount = $data['amount'] + $charge;
//                $amount = $data['amount']*(1+$config['ptr73']);
//                if($data['amount'] > $userData['z7'])
                if ($amount > $userData['z7']) {
                    ajax_return(1, '账户余额不足');
                }
                //BTC
                if ($config['ptr69'] < ($userData['day_money1'] + $data['amount'])) {
                    ajax_return(1, '超过每日限额');
                }


            } elseif ($data['coinname'] == 2) {
                //ETH2019052117
//                if ($config['ptr78'] > $data['amount'])
//                {
//                    ajax_return(1,'超过最低限额'.$config['ptr78']);
//                }
                //手续费扣除
                $charge = $data['amount'] * $config['ptr67'];
                $amount = $data['amount'] + $charge;
//                $amount = $data['amount']*(1+$config['ptr74']);
                if ($amount > $userData['z7']) {
                    ajax_return(1, '账户余额不足');
                }
//                //ETH
//                if ($config['ptr70'] < ($userData['day_money2']+$data['amount']))
//                {
//                    ajax_return(1,'超过每日限额');
//                }

            } elseif ($data['coinname'] == 3) {
                //USDT2019052117
//                if ($config['ptr79'] > $data['amount']) {
//                    ajax_return(1, '超过最低限额' . $config['ptr79']);
//                }
                //手续费扣除
                $charge = $data['amount'] * $config['ptr75'];
                $amount = $data['amount'] + $charge;
//                $amount= $data['amount']*(1+$config['ptr75']);
                if ($amount > $userData['z8']) {
                    ajax_return(1, '账户余额不足');
                }

                //USDT
                if ($config['ptr71'] < ($userData['day_money3'] + $data['amount'])) {
                    ajax_return(1, '超过每日限额');
                }

            } elseif ($data['coinname'] == 4) {
                //WFX2019052117
                if ($config['ptr80'] > $data['amount']) {
                    ajax_return(1, '超过最低限额' . $config['ptr80']);
                }
                //手续费扣除
                $charge = $data['amount'] * $config['ptr76'];
                $amount = $data['amount'] + $charge;
//                $amount = $data['amount']*(1+$config['ptr76']);
                if ($amount > $userData['z5']) {
                    ajax_return(1, '账户余额不足');
                }
                //WFX
                if ($config['ptr72'] < ($userData['day_money4'] + $data['amount'])) {
                    ajax_return(1, '超过每日限额');
                }
            } elseif ($data['coinname'] == 5) {
                //EASY20190731
                //手续费扣除
                $charge = $data['amount'] * $config['ptr76'];
                $amount = $data['amount'] + $charge;
                if ($amount > $userData['z11']) {
                    ajax_return(1, '账户余额不足');
                }
            }

            //数据入库
            $info['userid'] = $userid;
//            $info['phone'] = $userData['phone'];
            $info['phone'] = $userData['username'];
            if ($data['coinname'] == 1) {
                $info['coinname'] = 'btc';


            } elseif ($data['coinname'] == 2) {

//                $info['coinname'] = 'eth';
                $info['coinname'] = 'asset';

            } elseif ($data['coinname'] == 3) {

                $info['coinname'] = 'usdt';

            } elseif ($data['coinname'] == 4) {

                $info['coinname'] = 'wfx';
            } elseif ($data['coinname'] == 5) {

                $info['coinname'] = 'easy';
            }
//            $info['address'] = $data['address'];

//            //手续费扣除
//            $info['amount'] = $data['amount']*(1-$config['ptr76']);
            $info['amount'] = $data['amount'];
            $info['address'] = $data['address'];
            $info['fee'] = $charge;
            $info['type'] = 2;
            $info['status'] = 2;
            $info['addtime'] = time();

            $res1 = M('coinlist')->add($info);

            if ($data['coinname'] == 1) {
                //统计每日限额
                $res4 = M('user')->where(['id' => $userid])->setInc('day_money1', $amount);
                $res2 = M('user')->where(['id' => $userid])->setDec('z7', $amount);

            } elseif ($data['coinname'] == 2) {
                //统计每日限额
//                $res4= M('user')->where(['id'=>$userid])->setInc('day_money2',$amount);
                $res2 = M('user')->where(['id' => $userid])->setDec('z7', $amount);

            } elseif ($data['coinname'] == 3) {
                //统计每日限额
                $res4 = M('user')->where(['id' => $userid])->setInc('day_money3', $amount);
                $res2 = M('user')->where(['id' => $userid])->setDec('z8', $amount);

            } elseif ($data['coinname'] == 4) {
                //统计每日限额
                $res4 = M('user')->where(['id' => $userid])->setInc('day_money4', $amount);
                $res2 = M('user')->where(['id' => $userid])->setDec('z5', $amount);
            } elseif ($data['coinname'] == 5) {
                $res2 = M('user')->where(['id' => $userid])->setDec('z11', $amount);
            }
            if ($res1 && $res2) {
                //后台短信提醒
                send_msg_remind($userData['username'],date("Y-m-d H:i:s",time()));
                ajax_return(0, '申请成功');
            } else {
                ajax_return(1, '申请失败');
            }

        } else {
            $exp="^[a-z'0-9]+([._-][a-z'0-9]+)*@([a-z0-9]+([._-][a-z0-9]+))+$";
            if(preg_match($exp, $userData['username'])){ //先用正则表达式验证email格式的有效性
                $userData['type']=2;//邮箱
            } else{
                $userData['type']=1;//手机号
            }
            //获取账户信息
            $this->assign('userData', $userData);
            //判断是否生成钱包地址ASSET
            $this->assign('accountBalance', $userData['z7']);
            $this->assign('config', $config);
            $this->display();
        }
    }

    /**
     *提现页面
     * User: ming
     * Date: 2020/4/23 15:54
     */
    public function withdrawed()
    {
        $lid = I('lid') ? I('lid') : 0;
        //用户id
        $user_id = $this->user_info['id'];
        //获存币数量
        $lockData = M('locked')->where(['userid' => $user_id, 'id' => $lid])->find();
        if ($lockData) {
//            $month_time = strtotime("+1 months", $lockData['addtime']);//下个月时间戳
//            dump($month_time);die;
//            if ($month_time >= time()) {
//                $lockData['time_status'] = 1;//未满一个月
//            } else {
//                $lockData['time_status'] = 2;//满一个月
//            }
            $this->assign("lockData", $lockData);//获取数据
        }
//       $month_time= date("Y-m-d H:i:s", strtotime("+1 months", $lockData['addtime']));//下个月时间
//        dump($month_time); die;
        //获取账户信息
        $userData = M('user')->where(['id' => $user_id])->find();
        $this->assign('userData', $userData);
        //获取手续费参数
        $configData = M('reward_config')->find();
        $this->assign('configData', $configData);

        if (IS_POST) {
//            if ($userData['is_real'] != 2) {
//                $this->ajaxReturn(array('code' => '-1', 'message' => '请先到个人中心完成实名认证'));
////                ajax_return(1, '请先到个人中心完成实名认证');
//            }
            if ($configData['finance_toggle'] == 0){
                //2020 12 12 18:37
                //理财开关关闭
                $this->ajaxReturn(array());
            }
            if($userData['z2']<$configData['a53']){
                $this->ajaxreturn(array('code' => '-1', 'message' => '矿工费不足，使用USDT快速闪兑DACM'));
            }
            //接收参数
            $data = I('post.');
            if ($userData['password2'] != MD5($data['password2'])) {
                $this->ajaxReturn(array('code' => '-1', 'message' => '请输入正确的支付密码'));
            }
//            if($configData['canshu69'] == 0 )
//            {
//                $this->ajaxReturn(array('code'=>'-1','message'=>$configData['canshu70']));
//            }
//            if ($data['is_real'] != 2) {
//                $this->ajaxReturn(array('code' => '-2', 'message' => '请先完成实名认证'));
//            }
            $lockData = M('locked')->where(['userid' => $user_id, 'id' => $data['lid']])->find();
            if($lockData['status']=='1'){
                $this->ajaxReturn(array('code' => '-1', 'message' => '已经提取完成'));
            }
            $time=3600*24*30;
            //一个月内到全部到余额
            if (($lockData['addtime']+$time)>=time()) {
                $charge =$configData['a14'];
                //减去账户余额
                M('locked')->where(['id' => $data['lid']])->setDec('amount',$data['amount']);
                $balance = $data['amount']*(1 - $charge);//扣除手续费
                $coin_price=$configData['b2']*$balance;
                M('locked')->where(['id' => $data['lid']])->setDec('coin_price',$coin_price);//计算sweet值

//                if($configData['a53']>0){
//                    $user_arr['z2']=$userData['z2']-$configData['a53'];
//                    $this->add_fmoney($userData['id'],$userData['id'],$configData['a53'],53,2,'扣除固定DACM');
//                }
                $user_arr['z8']=$userData['z8']+$balance;
                $user_arr['z14']=$userData['z14']-$data['amount'];

                M('user')->where(['id' => $user_id])->save($user_arr);
                M('locked')->where(['id' => $data['lid']])->save(['status' => 1]);//已结束
                $this->add_fmoney_log($user_id,$user_id, $balance, 8, '本金归还USDT',  "12", $charge,$lockData['addtime']);
                $this->ajaxReturn(array('code' => '1', 'message' => '提取成功'));
            }else{
                if(($lockData['addtime']+$time*5)<time()){
                    $charge =$configData['a19'];
                }elseif (($lockData['addtime']+$time*4)<time()){
                    $charge =$configData['a18'];
                }elseif (($lockData['addtime']+$time*3)<time()){
                    $charge =$configData['a17'];
                }elseif (($lockData['addtime']+$time*2)<time()){
                    $charge =$configData['a16'];
//                }elseif (($lockData['addtime']+$time*1)<time()){
//                    $charge =$configData['a15'];
                }else{
//                    $this->ajaxReturn(array('code' => '-1', 'message' => '账号异常重新操作'));
//                    $charge =$configData['a14'];
                    $charge =$configData['a15'];
                }
                if ($data['amount'] > $lockData['amount']) {
                    $this->ajaxReturn(array('code' => '-1', 'message' => '账户余额不足'));
                }

                //减去账户余额
                $balance = $data['amount']*(1 - $charge);


                $price_from = "z" . $data['from'];//币种选择
                $balance_money=$lockData['amount']-$data['amount'];
                //资产包等级
                if ($balance_money >=50000){
                    $param['type'] = 8;
                }elseif($balance_money>=40000&&$balance_money<50000){
                    $param['type'] = 7;
                }elseif($balance_money>=30000&&$balance_money<40000){
                    $param['type'] = 6;
                }elseif($balance_money>=20000&&$balance_money<30000){
                    $param['type'] = 5;
                }elseif($balance_money>=10000&&$balance_money<20000){
                    $param['type'] = 4;
                }elseif($balance_money>=5000&&$balance_money<10000){
                    $param['type'] = 3;
                }elseif($balance_money>=1000&&$balance_money<5000){
                    $param['type'] = 2;
                }elseif($balance_money>=500&&$balance_money<1000){
                    $param['type'] = 1;
                }else{
                    $param['type'] =0;
                }
                M()->startTrans();
                //提取为0结束此存币信息可删除
                if($balance_money<=0){
                    M('locked')->where(['id' => $data['lid']])->save(['status' => 1]);//已结束
                }
                $res1 = M('locked')->where(['id' => $data['lid']])->setDec('amount',$data['amount']);
                $coin_price=$configData['b2']*$data['amount'];
                M('locked')->where(['id' => $data['lid']])->setDec('coin_price',$coin_price);//计算sweet值
                M('locked')->where(['id' => $data['lid']])->save(['type'=>$param['type']]);//更新等级

                $bj=$balance*$configData['a39'];//本金归还---扣除部分到股本20201128
                $gb=$balance*(1-$configData['a39']);//股本预存数量20201128

                $arr[$price_from]=$userData[$price_from]+$bj;//本金归还---扣除部分到股本20201128
                $arr['z17']=$userData['z17']+$gb;//股本预存数量20201128
                $arr['z16']=$userData['z16']+$gb;//股本总数量20201128
                $arr['z14']=$userData['z14']-$data['amount'];
                if($configData['a53']>0){
                    $arr['z2']=$userData['z2']-$configData['a53'];
                    $this->add_fmoney($userData['id'],$userData['id'],$configData['a53'],53,2,'扣除固定DACM');
                }

                $res2=  M('user')->where(['id' => $user_id])->save($arr);
//            $res3 = $this->add_fmoney_log($data['lid'], $user_id, $balance, $data['from'], '本金归还',  "12", $charge,$lockData['addtime']);
                $res3 = $this->add_fmoney_log($user_id, $user_id, $balance, $data['from'], '本金归还',  "12", $charge,$lockData['addtime']);
                //2020 12 12 18:47  理财股本划转记录
                $res4 = $this->add_fmoney_log($user_id, $user_id, $gb, 17, '理财股本划转',  "16", $charge,$lockData['addtime']);
//            $res4 = M('user')->where(['id' => $user_id])->setDec('z14', $data['amount']);//存币总额修改20200427
//            $res5 = M('user')->where(['id' => $user_id])->setInc('less_zong',$data['amount']);//存币补仓差额20200427
                if ($res1&&$res2&&$res3 && $res4) {
                    M()->commit();
                    $db = M();
                    $db->execute("call kt002($user_id,$balance)");
                    $money=$data['amount'];
                    $db->execute("call kt003_vip($user_id,$money)");
                    //超过额度
                    $db->execute("call up_level($user_id)");
//                if($userData['zuo_zong']>=$configData['a22']){
//                    //代理升级
//                    $this->reward($configData,$userData);
//                }
                    $this->ajaxReturn(array('code' => '1', 'message' => '提取成功'));
                } else {
                    M()->rollback();
                    $this->ajaxReturn(array('code' => '-1', 'message' => '提取失败'));
                }
            }


        } else {
            //获取存币生息提现记录
//            $where['user_id'] = $user_id;
//            $where['from_id'] = $lid;
//            $where['type'] = ['in', [7, 11]];//存币生息ASSET收益EASY收益
////            $where['reward_type'] = 712;
//            $where['reward_type'] = ['in', [712, 1112]];
//            $count = M('fmoney')->where($where)->count();
//            $Page = new \Think\Page($count, 4);
////            $Page->setConfig(prev, '上一页');
////            $Page->setConfig(next, '下一页');
//            $show = $Page->show();
//            $data = M('fmoney')->where($where)->limit($Page->firstRow . ',' . $Page->listRows)->order('id desc')->select();
//            $this->assign('chargeData', $data);
//            $this->assign('page', $show);
            $this->display();
        }
    }

    /**
     * 手续费判断
     * User: ming
     * Date: 2020/4/24 10:35
     */
    public function with_charge(){
        if(IS_POST){
            $data=I('post.');
            //用户id
            $user_id = $this->user_info['id'];
            //获取账户信息
        //    $userData = M('user')->where(['id' => $user_id])->find();
            //获取手续费参数
            $configData = M('reward_config')->find();

            $lockData = M('locked')->where(['userid' => $user_id, 'id' => $data['lid']])->find();
            if($lockData['status']=='1'){
                $this->ajaxReturn(array('code' => '-1', 'message' => '已经提取完成'));
            }
            if($data['amount']==""||$data['amount']<0){
                $this->ajaxReturn(array('code' => '-1', 'message' => ''));
            }
            $time=3600*24*30;
            if(($lockData['addtime']+$time*6)<time()){
                $charge ='第六个月及以前'.$configData['a19']*100 .'%';
            }elseif (($lockData['addtime']+$time*5)<time()){
                $charge ='第五个月'.$configData['a18']*100 .'%';;
            }elseif (($lockData['addtime']+$time*4)<time()){
                $charge ='第四个月'.$configData['a17']*100 .'%';;
            }elseif (($lockData['addtime']+$time*3)<time()){
                $charge ='第三个月'.$configData['a16']*100 .'%';;
            }elseif (($lockData['addtime']+$time*2)<time()){
                $charge ='第二个月'.$configData['a15']*100 .'%';;
            }else{
                $charge ='第一个月'.$configData['a14']*100 .'%';;
            }
            if ($data['amount'] > $lockData['amount']) {
                $this->ajaxReturn(array('code' => '-1', 'message' => '账户余额不足'));
            }
            $this->ajaxReturn(array('code' => '1', 'message' => $charge));
        }
    }

    /**
     * 资产包说明
     * User: ming
     * Date: 2020/4/24 14:00
     */
    public function content(){
        $this->display();
    }
    /**
     * 存币列表
     * User: ming
     * Date: 2020/4/23 16:29
     */
    public function locked_list()
    {
        //用户id
        $user_id = $this->user_info['id'];

        //获取锁仓记录
        $where['userid'] = $user_id;
        $count = M('locked')->where($where)->count();
        $Page = new \Think\Page($count, 8);
//        $Page->setConfig(prev, '上一页');
//        $Page->setConfig(next, '下一页');
        $show = $Page->show();
        $data = M('locked')->where($where)->limit($Page->firstRow . ',' . $Page->listRows)->order('id desc')->select();
        $this->assign('lockData', $data);
        $this->assign('page', $show);
        $config = M('reward_config')->where('id=1')->field('finance_toggle')->find();
        $this->assign('config',$config);

        $this->display();
    }
    //记录理财关闭后点击的次数 （一天一次）
    public function record_lock(){
        $user_id = $this->user_info['id'];
        $todayBegin = strtotime(date('Y-m-d'));
        $where['create_time'] = array('between',[$todayBegin,time()]);
        $where['user_id'] = $user_id;
        $where['type'] = 7;
        $where['reward_type'] = 123;
        $check = M('fmoney')->where($where)->find();
        if (!$check){
            //今日没有点击理财划转
            $this->add_fmoney_log($user_id,$user_id,0,7,'划转未成功',123);
        }
        ajax_return(0, '');
    }
    //获取账户余额
    public function getBalance()
    {
        $data = I('post.');

        //dump($data);

        $userid = $this->user_info['id'];
        $userData = M('user')->where(['id' => $userid])->find();
        if ($data['coinname'] == 1) {
            ajax_return(0, 'BTC', $userData['z7']);

        } elseif ($data['coinname'] == 2) {
//            ajax_return(0,'ETH',$userData['z9']);
            ajax_return(0, 'DACM', $userData['z2']);

        } elseif ($data['coinname'] == 8) {

            ajax_return(0, 'USDT', $userData['z8']);

        }
    }

    /**
     * 兑换页面
     * User: ming
     * Date: 2019/7/17 18:38
     */
    public function transfer()
    {
        //用户id
        $user_id = $this->user_info['id'];
        //获取账户信息
        $userData = M('user')->where(['id' => $user_id])->find();
        //获取手续费参数
        $configData = M('reward_config')->find();

        if (IS_POST) {
//            if ($userData['is_real'] != 2) {
//                $this->ajaxReturn(array('code' => '-1', 'message' => '请先到个人中心完成实名认证'));
////                ajax_return(1, '请先到个人中心完成实名认证');
//            }

            //接收参数
            $data = I('post.');
            //dump($data);die();

//            if($configData['canshu69'] == 0 )
//            {
//                $this->ajaxReturn(array('code'=>'-1','message'=>$configData['canshu70']));
//            }

            if ($data['amount'] == '' || $data['amount'] <= 0) {
                $this->ajaxReturn(array('code' => '-1', 'message' => '信息不完整'));
            }

//            if($data['amount']  < $configData['ptr66'])
//            {
//                $this->ajaxReturn(array('code'=>'-1','message'=>'兑换数量不能小于'.$configData['ptr66']));
//            }
            if ($data['from'] == $data['to']) {
                $this->ajaxReturn(array('code' => '-1', 'message' => '自己不能跟自己兑换'));
            }

            $charge = $data['amount'] * $configData['ptr68'];//闪兑手续费
            $coinFrom = "z" . $data['from'];//币名
            $coinTo = "z" . $data['to'];//币名
            if ($data['amount'] + $charge > $userData[$coinFrom]) {
                $this->ajaxReturn(array('code' => '-1', 'message' => '账户余额不足'));
            }
            $asset_price = $this->asset_price();//asset实时价格
            $easy_price = $this->easy_price();//easy实时价格

//            if (!S('asset_price')) {
//                $asset_price = $this->asset_price();
//            } else {
//                $asset_price = S('asset_price');
//            }
            $rate = $this->finance_rate();//美元兑换人民币价格

            //ASSET兑换
            if ($data['from'] == 7) {
                $price = $data['amount'] * $asset_price;//USDT

                //20190805
                if ($data['to'] == 8) {
                    $this->ajaxReturn(array('code' => '-1', 'message' => 'ASSET不能兑换USDT'));
                }
                //兑换成资产券
                if ($data['to'] == 1) {
                    $price = $price * $rate;//兑换成人民币
                }
                //兑换成EASY
                if ($data['to'] == 11) {
                    $price = $price / $easy_price;//兑换成EASY
                }
            }
            //USDT兑换
            if ($data['from'] == 8) {
                //兑换成资产券
                if ($data['to'] == 1) {
                    $price = $data['amount'] * $rate;//兑换成人民币

                }
                //兑换成ASSET
                if ($data['to'] == 7) {
                    $price = round($data['amount'] / $asset_price, 4);//兑换成asset
                }
                //兑换成EASY
                if ($data['to'] == 11) {
                    $price = round($data['amount'] / $easy_price, 4);//兑换成EASY
                }
            }
            //资产券兑换
            if ($data['from'] == 1) {
                $price = round($data['amount'] / $rate, 4);

                //兑换成ASSET
                if ($data['to'] == 7) {
                    $price = round($price / $asset_price, 4);//兑换成ASSET
                }
                //兑换成EASY
                if ($data['to'] == 11) {
                    $price = round($price / $easy_price, 4);//兑换成EASY
                }
            }

            //EASY兑换
            if ($data['from'] == 11) {
                //20190805
                if ($data['to'] == 8) {
                    $this->ajaxReturn(array('code' => '-1', 'message' => 'EASY不能兑换USDT'));
                }

                $price = $data['amount'] * $easy_price;//USDT
                //兑换成资产券
                if ($data['to'] == 1) {
                    $price = $price * $rate;//兑换成人民币
                }
                //兑换成ASSET
                if ($data['to'] == 7) {
                    $price = $price / $asset_price;//兑换成ASSET
                }
            }
            //减去账户余额
            $res1 = M('user')->where(['id' => $user_id])->setDec($coinFrom, $data['amount'] + $charge);
            $res2 = $this->add_log($user_id, $user_id, -($data['amount'] + $charge), $data['from'], '闪兑', "30" . $data['from'], $charge);

            //增加兑换
//            $res3 = M('user')->where(['id'=>$user_id])->setInc($coinTo, $data['amount']);
            $res3 = M('user')->where(['id' => $user_id])->setInc($coinTo, $price);
            $res4 = $this->add_log($user_id, $user_id, $price, $data['to'], '闪兑', "31" . $data['to'], $charge);

            if ($res1 && $res2 && $res3 && $res4) {
                $this->ajaxReturn(array('code' => '1', 'message' => '兑换成功'));
            } else {
                $this->ajaxReturn(array('code' => '-1', 'message' => '兑换失败'));
            }

        } else {

            $this->assign('userData', $userData);
            $this->assign('configData', $configData);
            $this->display();
        }
    }

    /**
     * 存币生息
     * User: ming
     * Date: 2019/7/18 10:40
     */
    public function live()
    {
        //用户id
        $user_id = $this->user_info['id'];
        //获取账户信息
        $userData = M('user')->where(['id' => $user_id])->find();
        //获取手续费参数
        $configData = M('reward_config')->find();
        if (IS_POST) {
            //接收参数
            $data = I('post.');
//            if ($configData['finance_toggle'] == 0){
//                $this->ajaxReturn(array('code' => '-1', 'message' => '暂未开放！'));
//            }
//            if($configData['canshu69'] == 0 )
//            {
//                $this->ajaxReturn(array('code'=>'-1','message'=>$configData['canshu70']));
////            }
//            if ($userData['is_real'] != 2) {
//                $this->ajaxReturn(array('code' => '-1', 'message' => '请先到个人中心完成实名认证'));
//            }
            if ($data['amount'] == '') {
                $this->ajaxReturn(array('code' => '-1', 'message' => '信息不完整'));
            }
            if($data['amount']<0){
                $this->ajaxReturn(array('code' => '-1', 'message' => '请输入正确的数量'));
            }

            if($data['amount']<$configData['a5']){
                $this->ajaxReturn(array('code' => '-1', 'message' => '最低限额USDT'.$configData['a5']));
            }

            //收益范围
            if ($configData['a3']>$data['amount']||$data['amount']>$configData['a4']) {
//                $this->ajaxReturn(array('code' => '-1', 'message' => '超过单笔理财额度'));
                $this->ajaxReturn(array('code' => '-1', 'message' => '请输入规划范围内的额度'));
            }

            //支付密码20191114
            if (md5($data['password']) != $userData['password2']) {
                $this->ajaxReturn(array('code' => '-1', 'message' => '请输入正确的密码'));
            }

            $coinFrom = "z" . $data['from'];//币名
            //判断余额
            if ($data['amount'] > $userData[$coinFrom]) {
                $this->ajaxReturn(array('code' => '-1', 'message' => '账户余额不足'));
            }
//                $rate = $this->finance_rate();//美元价格
                $rate = $configData['b2'];//美元价格
                $param['amount']=$data['amount'];
                $param['coin_price'] =round($data['amount'] * $rate, 4);;//sweet币价格


            //资产包等级
            if ($param['amount'] >=50000){
                $param['type'] = 8;
            }elseif($param['amount']>=40000&&$param['amount']<50000){
                $param['type'] = 7;
            }elseif($param['amount']>=30000&&$param['amount']<40000){
                $param['type'] = 6;
            }elseif($param['amount']>=20000&&$param['amount']<30000){
                $param['type'] = 5;
            }elseif($param['amount']>=10000&&$param['amount']<20000){
                $param['type'] = 4;
            }elseif($param['amount']>=5000&&$param['amount']<10000){
                $param['type'] = 3;
            }elseif($param['amount']>=1000&&$param['amount']<5000){
                $param['type'] = 2;
            }elseif($param['amount']>=500&&$param['amount']<1000){
                $param['type'] = 1;
            }else{
                $param['type'] =0;
            }
//            $info=M('locked')->where(['userid'=>$user_id,'is_class'=>1])->find();//存币，没有信托
//            if(!$info){
//                $hid=M('user')->where(['id'=>$user_id])->getField('higher_id');
//                M('user')->where(['id' => $hid])->setInc('tj_count1');//存币激活20191112
//            }

         
            M()->startTrans();
            //减去账户余额
            $res1 = M('user')->where(['id' => $user_id])->setDec($coinFrom, $data['amount']);
            $res2 = M('user')->where(['id' => $user_id])->setInc('z14', $data['amount']);//USDT存币总额
            $res5 = M('user')->where(['id' => $user_id])->setInc('zuo_zong', $data['amount']);//USDT存币总额
            $res3 = $this->add_fmoney_log($user_id, $user_id, $data['amount'], $data['from'], '理财资产包', "10" . $data['from']);

            $asset_num=$userData['z14']+$data['amount'];

            if($asset_num>=$configData['a63']*$userData['z19_asset']){//购买数量大于2倍的原资产数量满足继续收益
                M('user')->where(['id' => $user_id])->save(['sy_status'=>0]);
            }else{
                $diff_num=$configData['a63']*$userData['z19_asset']-$userData['z14'];//差的资产包数量

                $this->ajaxReturn(array('code' => '-1', 'message' => '需要购买'.$diff_num.'USDT以上'));
            }

            $param['userid'] = $user_id;
            $param['addtime'] = time();
//            $param['start_time'] = time()+24*3600;//第二天时间
            $param['start_time'] = time();//测试用20200415
            $param['coin_type'] = $data['from'];//币种20190801
            $res4 = M('locked')->add($param);//存币生息
//            if($userData['is_empty']!=2){
//                M('user')->where(['id' => $user_id])->save(['is_empty'=>2]);//存币激活状态20191118
//            }
            if ($res1 && $res2 && $res3 && $res4&&$res5) {
                M()->commit();
                $db = M();
                $money = $param['amount'];//USDT
                $db->execute("call kt001($user_id,$money)");
                $db->execute("call up_level($user_id)");
                //超过额度
//                $zong_zong= M('locked')->where(['userid'=>$user_id,'status'=>0])->sum();
//               if($zong_zong>=$configData['a22']){
//                    //代理升级
//                    $this->reward($configData,$userData,$zong_zong);
//               }
                $this->ajaxReturn(array('code' => '1', 'message' => '操作成功'));
            } else {
                M()->rollback();
                $this->ajaxReturn(array('code' => '-1', 'message' => '操作失败'));
            }

        } else {
            $this->assign('userData', $userData);
            $this->assign('configData', $configData);
            $this->display();
        }
    }

    /**
     * 转账页面
     */
//	public function transfer()
//	{
//		if(IS_POST)
//		{
//			//接收参数
//			$data = I('post.');
//			//dump($data);die();
//
//			//用户id
//			$user_id = $this->user_info['id'];
//
//			//获取账户信息
//			$userData = M('admin')->where(['id'=>$user_id])->find();
//			$this->assign('userData', $userData);
//
//			//获取手续费参数
//			$configData = M('config')->find();
//			$this->assign('configData', $configData);
//
//			if($configData['canshu69'] == 0 )
//			{
//				$this->ajaxReturn(array('code'=>'-1','message'=>$configData['canshu70']));
//			}
//
//			if($data['amount'] == '' || $data['mobile'] == '')
//			{
//				$this->ajaxReturn(array('code'=>'-1','message'=>'转账信息不完整'));
//			}
//
//			//转发用户是否存在
//			$ownerData = M('admin')->where(['usernames'=>$data['mobile']])->find();
//			if(empty($ownerData))
//			{
//				$this->ajaxReturn(array('code'=>'-1','message'=>'用户手机号不存在'));
//			}
//
//			//不能转给自己
//			if($ownerData['id'] == $user_id)
//			{
//				$this->ajaxReturn(array('code'=>'-1','message'=>'不能转账给自己'));
//			}
//
//			if($data['amount']  < $configData['canshu18'])
//			{
//				$this->ajaxReturn(array('code'=>'-1','message'=>'提币数量不能小于'.$configData['canshu18']));
//			}
//
//			if($data['amount'] + $configData['canshu4'] > $userData['reward1'])
//			{
//				$this->ajaxReturn(array('code'=>'-1','message'=>'账户余额不足'));
//			}
//
//
//			$data['fromid'] = $user_id;
//			$data['fromname'] = $userData['usernames'];
//			$data['ownerid'] = $ownerData['id'];
//			$data['ownername'] = $ownerData['usernames'];
//			$data['addtime'] = time();
//			$data['sendamount'] = $data['amount'] / $btcPrice['canshu60'];
//			$data['fee'] = $configData['canshu4'];
//			$data['type'] = 1;
//			$data['status'] = 1;
//
//			//数据入库
//			$res1 = M('transfer')->add($data);
//			//增加记录
//			$res2 = $this->add_log($user_id, $user_id, $data['amount'], 11, '用户转账');
//			//减去账户余额
//			$res3 = M('admin')->where(['id'=>$user_id])->setDec('reward1', $data['amount']+$data['fee']);
//
//			//增加转账增加锁仓金额
//			//$res4 = M('admin')->where(['usernames'=>$data['mobile']])->setInc('reward1', $data['amount']);
//
//			$transferId = M('admin')->where(['usernames'=>$data['mobile']])->find();
//
//			//判断是否有锁仓记录
//            $typeData = M('locked')->where(['userid'=>$transferId['id']])->find();
//
//            //如果一条没有直接插入即可
//            if(empty($typeData))
//            {
//
//                //锁仓入库
//                $info['amount'] = $data['amount'];
//                $info['userid'] = $transferId['id'];
//                $info['addtime'] = time();
//
//                $res1 = M('locked')->add($info);
//
//                //锁仓记录入库
//                $res2 = $this->add_log($user_id, $transferId['id'], $data['amount'], 7, '用户锁仓');
//
//                if($res1 && $res2)
//                {
//                    //$this->ajaxReturn(array('code'=>'1','message'=>'锁仓成功'));
//                }else
//                {
//                    //$this->ajaxReturn(array('code'=>'-1','message'=>'锁仓失败'));
//                }
//
//            }else
//            {
//
//                $info['amount'] = $typeData['amount'] + $data['amount'];
//                $res1 = M('locked')->where(['userid'=>$transferId['id']])->save($info);
//
//                //插入追加记录
//                $res2 = $this->add_log($user_id,$transferId['id'], $data['amount'], 7, '用户追加锁仓');
//
//                if($res1 && $res2)
//                {
//                    //$this->ajaxReturn(array('code'=>'1','message'=>'追加锁仓成功'));
//                }else
//                {
//                    //$this->ajaxReturn(array('code'=>'-1','message'=>'追加锁仓失败'));
//                }
//            }
//
//			if($res1 && $res2 && $res3)
//			{
//				$this->ajaxReturn(array('code'=>'1','message'=>'转账成功'));
//			}else
//			{
//				$this->ajaxReturn(array('code'=>'-1','message'=>'转账失败'));
//			}
//
//		}else
//		{
//
//			//用户id
//			$user_id = $this->user_info['id'];
//
//			//获取账户信息
//			$userData = M('user')->where(['id'=>$user_id])->find();
//			$this->assign('userData', $userData);
//
//			//获取手续费参数
//			$configData = M('reward_config')->find();
//			$this->assign('configData', $configData);
//
//			//获取btc实时价格
//	        $btcPrice = M('reward_config')->find();
//	        $this->assign('btcPrice', 1);
//
//			$this->display();
//		}
//	}

    /**
     * 历史记录
     */
    public function history()
    {
        //用户id
        $user_id = $this->user_info['id'];
        $where4['user_id'] = $user_id;
        $where4['type'] = array('in', [2,8]);//20191125
        $where4['reward_type'] = 18;//互转记录
        $count4 = M('fmoney')->where($where4)->count();
        $Page4 = new \Think\Page($count4, 8);
        $Page4->rollPage = 8; //控制最大页码显示数放在实例化page后面就成
        $show4 = $Page4->show();
        $Data = M('fmoney')->where($where4)->limit($Page4->firstRow . ',' . $Page4->listRows)->order('id desc')->select();
        $this->assign('data', $Data);
        $this->assign('page4', $show4);

        $this->display();
    }

    /**
     * 业绩明细
     * User: ming
     * Date: 2019/10/31 13:51
     */
    public function performance(){
        //用户id
        $user_id = $this->user_info['id'];

        //类型判断
        $type = I('type') ? I('type') : 2;
        $this->assign('type', $type);

        //获取团队记录
//        if($type==2){
        $where2['user_id'] = $user_id;
        $where2['type'] = 9;
        $where2['reward_type'] = array('in', [31, 32, 33]);
//        $where2['tips'] = '存币生息';
        $count = M('fmoney')->where($where2)->count();
        $Page2 = new \Think\Page($count, 5);
        $Page2->rollPage = 8; //控制最大页码显示数放在实例化page后面就成
        $show2 = $Page2->show();
        $data = M('fmoney')->where($where2)->limit($Page2->firstRow . ',' . $Page2->listRows)->order('id desc')->select();
        $this->assign('transferData', $data);
        $this->assign('page2', $show2);
        $price=M('fmoney')->where($where2)->sum('amount');
       $asset_price =$this->asset_price();
       $att['all_profit_money']=$price*$asset_price;//美金

        $yesterday =strtotime(date('Y-m-d',strtotime("-1 day")));;
        //获得当日凌晨的时间戳
        $today = strtotime(date("Y-m-d"),time());
        $where2['create_time'] = ['between',[$yesterday,$today]];//当时明细

        $yesterday_price=M('fmoney')->where($where2)->sum('amount');
        $att['all_yesterday_money']=$yesterday_price*$asset_price;
        $this->assign('att', $att);
//        }
//        if($type==3){
        //获取每日增加的明细
        //获得当日凌晨的时间戳
        $today = strtotime(date("Y-m-d"),time());
        $where3['create_time'] = ['gt',$today];//当时明细
        $where3['user_id'] = $user_id;
//        $where3['type'] = 9;
//        $where3['type'] = array('in', [9, 12]);//20190802
//        $where3['reward_typ'] = array('in', [1, 2, 3]);
        $count3 = M('fmoney')->where($where3)->count();
//        $count3 = M('withdraw')->where(['fromid'=>$user_id])->count();
        $Page3 = new \Think\Page($count3, 8);
        $Page3->rollPage = 8; //控制最大页码显示数放在实例化page后面就成
        $show3 = $Page3->show();
        $withdrawData = M('fmoney')->where($where3)->limit($Page3->firstRow . ',' . $Page3->listRows)->order('id desc')->select();
        $this->assign('withdrawData', $withdrawData);
        $this->assign('page3', $show3);

        $userid = $this->user_info['id'];
        $userData = M('user')->where(['id' => $userid])->find();
        $this->assign('user', $userData);
        $this->display();
//        }
    }
    //BTC查询
    public function getBtc()
    {

        $userid = $this->user_info['id'];
        $userData = M('user')->where(['id' => $userid])->find();

        $map['coinname'] = 'btc';
        $map['type'] = 1;
        $map['userid'] = $userid;

        $data = M('coinlist')->where($map)->find();

        //如果数据库不存在则去查询区块数据
        if (!$data) {

            $CoinClient = CoinClient('bitcoinrpc', 'bitcoinrpc', '127.0.0.1', '8332', 5, array(), 1);

            $json = $CoinClient->getwalletinfo();

            if (!isset($json['walletversion']) || !$json['walletversion']) {
                ajax_return(1, '钱包连接失败');
            }

            $resData = $CoinClient->listtransactions();

            //再判断区块中是否有数据
            if ($resData) {
                //如果存在数据入库
                foreach ($resData as $k => $v) {
                    if ($v['category'] == 'receive' && $v['label'] == $userData['phone']) {
                        //交易数据入库
                        $info['userid'] = $userid;
                        $info['phone'] = $userData['phone']?$userData['phone']:$userData['username'];
                        $info['coinname'] = 'btc';
                        $info['address'] = $v['address'];
                        $info['hash'] = $v['txid'];
                        $info['amount'] = $v['amount'];
                        $info['fee'] = 0;
                        $info['type'] = 1; //1 充币 2提币
                        $info['addtime'] = $v['time'];
                        $info['endtime'] = time();
                        $info['status'] = 1; // 1 已完成 2审核中

                        //充值记录入库
                        M('coinlist')->add($info);

                        //账户中增加余额
                        M('user')->where(['id' => $userid])->setInc('z7', $v['amount']);
                    }
                }
            }

        } else {//如果数据库里不为空，再去区块里查询

            $CoinClient = CoinClient('bitcoinrpc', 'bitcoinrpc', '127.0.0.1', '8332', 5, array(), 1);

            $json = $CoinClient->getwalletinfo();

            if (!isset($json['walletversion']) || !$json['walletversion']) {
                ajax_return(1, '钱包连接失败');
            }

            $resData = $CoinClient->listtransactions();

            //再判断区块中是否有数据
            if ($resData) {
                //如果存在数据入库
                foreach ($resData as $k => $v) {
                    if ($v['category'] == 'receive' && $v['label'] == $userData['phone']) {
                        //再判断数据是否已经插入到数据库中
                        $isempty = M('coinlist')->where(['hash' => $v['txid']])->find();

                        if (!$isempty) {
                            //交易数据入库
                            $info['userid'] = $userid;
                            $info['phone'] = $userData['phone']?$userData['phone']:$userData['username'];
                            $info['coinname'] = 'btc';
                            $info['address'] = $v['address'];
                            $info['hash'] = $v['txid'];
                            $info['amount'] = $v['amount'];
                            $info['fee'] = 0;
                            $info['type'] = 1; //1 充币 2提币
                            $info['addtime'] = $v['time'];
                            $info['endtime'] = time();
                            $info['status'] = 1; // 1 已完成 2审核中

                            //充值记录入库
                            M('coinlist')->add($info);

                            //账户中增加余额
                            M('user')->where(['id' => $userid])->setInc('z7', $v['amount']);
                        }
                    }
                }
            }

        }

    }

    //ETH查询
    public function getETH()
    {

        $userid = $this->user_info['id'];
        $userData = M('user')->where(['id' => $userid])->find();

        $map['coinname'] = 'eth';
        $map['type'] = 1;
        $map['userid'] = $userid;

        $data = M('coinlist')->where($map)->find();

        //判断数据库里没有充值记录，则去区块中查询
        if (!$data) {

            //$userData['eth_address'] = '0xE3c78b49cfAfe43Bc62Ca149F3B7f144C59ED9E7';

            $url = "http://api.etherscan.io/api?module=account&action=txlist&address=" . $userData['eth_address'] . "&startblock=0&endblock=99999999&sort=asc&apikey=H4R65KDWH86I2T8CD8R4ZU5TCXBAX8M7PR";

            $resUrl = requestGet($url);

            $res = json_decode($resUrl, true);

            if ($res['status'] == 1 && !empty($res['result'])) {

                foreach ($res['result'] as $k => $v) {

                    if ($v['value'] / 1000000000000000000 > 0 && $v['to'] == strtolower($userData['eth_address'])) {

                        //交易数据入库
                        $info['userid'] = $userid;
                        $info['phone'] = $userData['phone']?$userData['phone']:$userData['username'];
                        $info['coinname'] = 'eth';
                        $info['address'] = $v['to'];
                        $info['hash'] = $v['hash'];
                        $info['amount'] = $v['value'] / 1000000000000000000;
                        $info['fee'] = 0;
                        $info['type'] = 1;
                        $info['addtime'] = $v['timeStamp'];
                        $info['endtime'] = time();
                        $info['status'] = 1;

                        //充值记录入库
                        M('coinlist')->add($info);

                        //账户中增加余额
                        M('user')->where(['id' => $userid])->setInc('z9', $v['value'] / 1000000000000000000);

                    }
                }
            }

        } else {
            //数据库中已经有充值记录，则查询区块并判断

            //$userData['eth_address'] = '0xE3c78b49cfAfe43Bc62Ca149F3B7f144C59ED9E7';

            $url = "http://api.etherscan.io/api?module=account&action=txlist&address=" . $userData['eth_address'] . "&startblock=0&endblock=99999999&sort=asc&apikey=H4R65KDWH86I2T8CD8R4ZU5TCXBAX8M7PR";

            $resUrl = requestGet($url);

            $res = json_decode($resUrl, true);

            if ($res['status'] == 1 && !empty($res['result'])) {

                foreach ($res['result'] as $k => $v) {

                    if ($v['value'] / 1000000000000000000 > 0 && $v['to'] == strtolower($userData['eth_address'])) {
                        //再判断数据是否已经插入到数据库中
                        $isempty = M('coinlist')->where(['hash' => $v['hash']])->find();

                        if (!$isempty) {
                            //交易数据入库
                            $info['userid'] = $userid;
                            $info['phone'] = $userData['phone']?$userData['phone']:$userData['username'];
                            $info['coinname'] = 'eth';
                            $info['address'] = $v['to'];
                            $info['hash'] = $v['hash'];
                            $info['amount'] = $v['value'] / 1000000000000000000;
                            $info['fee'] = 0;
                            $info['type'] = 1;
                            $info['addtime'] = $v['timeStamp'];
                            $info['endtime'] = time();
                            $info['status'] = 1;

                            //充值记录入库
                            M('coinlist')->add($info);

                            //账户中增加余额
                            M('user')->where(['id' => $userid])->setInc('z9', $v['value'] / 1000000000000000000);
                        }
                    }
                }
            }

        }
    }

    //USDT查询
    public function getUSDT()
    {
        $userid = $this->user_info['id'];
        $userData = M('user')->where(['id' => $userid])->find();

        $map['coinname'] = 'usdt';
        $map['type'] = 1;
        $map['userid'] = $userid;

        $data = M('coinlist')->where($map)->find();

        //判断数据库里没有充值记录，则去区块中查询
        if (!$data) {

            //$userData['eth_address'] = '0xE3c78b49cfAfe43Bc62Ca149F3B7f144C59ED9E7';

            $url = "http://api.etherscan.io/api?module=account&action=tokentx&address=" . $userData['eth_address'] . "&startblock=0&endblock=999999999&sort=asc&apikey=H4R65KDWH86I2T8CD8R4ZU5TCXBAX8M7PR";
//            $url = "http://api.etherscan.io/api?module=account&action=tokentx&address=".$userData['usdt_address']."&startblock=0&endblock=999999999&sort=asc&apikey=H4R65KDWH86I2T8CD8R4ZU5TCXBAX8M7PR";

            $resUrl = requestGet($url);

            $res = json_decode($resUrl, true);

            if ($res['status'] == 1 && !empty($res['result'])) {

                foreach ($res['result'] as $k => $v) {
                    if ($v['value'] / 1000000 > 0 && $v['tokenSymbol'] == 'USDT' && $v['to'] == strtolower($userData['eth_address']) && $v['contractAddress'] == '0xdac17f958d2ee523a2206206994597c13d831ec7') //                    if($v['value'] / 1000000 > 0 && $v['tokenSymbol'] == 'USDT' && $v['to'] == strtolower($userData['usdt_address']) && $v['contractAddress'] == '0xdac17f958d2ee523a2206206994597c13d831ec7')
                    {

                        //交易数据入库
                        $info['userid'] = $userid;
                        $info['phone'] = $userData['phone']?$userData['phone']:$userData['username'];
                        $info['coinname'] = 'usdt';
                        $info['address'] = $v['to'];
                        $info['hash'] = $v['hash'];
                        $info['amount'] = $v['value'] / 1000000;
                        $info['fee'] = 0;
                        $info['type'] = 1;
                        $info['addtime'] = $v['timeStamp'];
                        $info['endtime'] = time();
                        $info['status'] = 1;

                        //充值记录入库
                        M('coinlist')->add($info);

                        //账户中增加余额
                        M('user')->where(['id' => $userid])->setInc('z8', $v['value'] / 1000000);

                    }
                }
            }

        } else {

            //判断数据库里没有充值记录，则去区块中查询

            //$userData['eth_address'] = '0xE3c78b49cfAfe43Bc62Ca149F3B7f144C59ED9E7';

            $url = "http://api.etherscan.io/api?module=account&action=tokentx&address=" . $userData['eth_address'] . "&startblock=0&endblock=999999999&sort=asc&apikey=H4R65KDWH86I2T8CD8R4ZU5TCXBAX8M7PR";

            $resUrl = requestGet($url);

            $res = json_decode($resUrl, true);

            if ($res['status'] == 1 && !empty($res['result'])) {

                foreach ($res['result'] as $k => $v) {

                    if ($v['value'] / 1000000 > 0 && $v['tokenSymbol'] == 'USDT' && $v['to'] == strtolower($userData['eth_address']) && $v['contractAddress'] == '0xdac17f958d2ee523a2206206994597c13d831ec7') {

                        //再判断数据是否已经插入到数据库中
                        $isempty = M('coinlist')->where(['hash' => $v['hash']])->find();

                        if (!$isempty) {

                            //交易数据入库
                            $info['userid'] = $userid;
                            $info['phone'] =  $userData['phone']?$userData['phone']:$userData['username'];
                            $info['coinname'] = 'usdt';
                            $info['address'] = $v['to'];
                            $info['hash'] = $v['hash'];
                            $info['amount'] = $v['value'] / 1000000;
                            $info['fee'] = 0;
                            $info['type'] = 1;
                            $info['addtime'] = $v['timeStamp'];
                            $info['endtime'] = time();
                            $info['status'] = 1;

                            //充值记录入库
                            M('coinlist')->add($info);

                            //账户中增加余额
                            M('user')->where(['id' => $userid])->setInc('z8', $v['value'] / 1000000);

                        }
                    }
                }
            }

        }


    }

    //WFX查询
    public function getWFX()
    {

        $userid = $this->user_info['id'];
        $userData = M('user')->where(['id' => $userid])->find();

        $map['coinname'] = 'asset';
        $map['type'] = 1;
        $map['userid'] = $userid;

        $data = M('coinlist')->where($map)->find();

        //判断数据库里没有充值记录，则去区块中查询
        if (!$data) {

            //$userData['eth_address'] = '0x61cb9627e11689d491be1b883c33280c736f38e1';

            $url = "http://api.etherscan.io/api?module=account&action=tokentx&address=" . $userData['eth_address'] . "&startblock=0&endblock=999999999&sort=asc&apikey=H4R65KDWH86I2T8CD8R4ZU5TCXBAX8M7PR";

            $resUrl = requestGet($url);

            $res = json_decode($resUrl, true);
//dump($res);die;
            if ($res['status'] == 1 && !empty($res['result'])) {

                foreach ($res['result'] as $k => $v) {

//                    if($v['value'] / 1000000000000000000 > 0 && $v['to'] == strtolower($userData['eth_address']) && $v['contractAddress'] == '0xba1ed22c69ad00739ee2b4abd70e270be9e87ee2')
                    if ($v['value'] / 1000000000000000000 > 0 && $v['to'] == strtolower($userData['eth_address']) && $v['contractAddress'] == '0x3ca98516fb32ca33c03b3687013781d8d8e48c7a') {

                        //交易数据入库
                        $info['userid'] = $userid;
//                        $info['phone'] = $userData['phone'];
                        $info['phone'] =  $userData['phone']?$userData['phone']:$userData['username'];
                        $info['coinname'] = 'asset';
                        $info['address'] = $v['to'];
                        $info['hash'] = $v['hash'];
                        $info['amount'] = $v['value'] / 1000000000000000000;
                        $info['fee'] = 0;
                        $info['type'] = 1;
                        $info['addtime'] = $v['timeStamp'];
                        $info['endtime'] = time();
                        $info['status'] = 1;

                        //充值记录入库
                        M('coinlist')->add($info);

                        //账户中增加余额
                        M('user')->where(['id' => $userid])->setInc('z7', $v['value'] / 1000000000000000000);
                    }
                }
            }
        } else {

            //判断数据库里没有充值记录，则去区块中查询

            //$userData['eth_address'] = '0x61cb9627e11689d491be1b883c33280c736f38e1';

            $url = "http://api.etherscan.io/api?module=account&action=tokentx&address=" . $userData['eth_address'] . "&startblock=0&endblock=999999999&sort=asc&apikey=H4R65KDWH86I2T8CD8R4ZU5TCXBAX8M7PR";

            $resUrl = requestGet($url);

            $res = json_decode($resUrl, true);

            if ($res['status'] == 1 && !empty($res['result'])) {

                foreach ($res['result'] as $k => $v) {

//                    if($v['value'] / 1000000000000000000 > 0 && $v['to'] == strtolower($userData['eth_address']) && $v['contractAddress'] == '0xba1ed22c69ad00739ee2b4abd70e270be9e87ee2')
                    if ($v['value'] / 1000000000000000000 > 0 && $v['to'] == strtolower($userData['eth_address']) && $v['contractAddress'] == '0x3ca98516fb32ca33c03b3687013781d8d8e48c7a') {

                        //再判断数据是否已经插入到数据库中
                        $isempty = M('coinlist')->where(['hash' => $v['hash']])->find();

                        if (!$isempty) {

                            //交易数据入库
                            $info['userid'] = $userid;
//                            $info['phone'] = $userData['phone'];
                            $info['phone'] = $userData['username'];
                            $info['coinname'] = 'asset';
                            $info['address'] = $v['to'];
                            $info['hash'] = $v['hash'];
                            $info['amount'] = $v['value'] / 1000000000000000000;
                            $info['fee'] = 0;
                            $info['type'] = 1;
                            $info['addtime'] = $v['timeStamp'];
                            $info['endtime'] = time();
                            $info['status'] = 1;

                            //充值记录入库
                            M('coinlist')->add($info);

                            //账户中增加余额
                            M('user')->where(['id' => $userid])->setInc('z7', $v['value'] / 1000000000000000000);
                        }
                    }
                }
            }
        }

    }

    //EASY查询
    public function getEASY()
    {

        $userid = $this->user_info['id'];
        $userData = M('user')->where(['id' => $userid])->find();

        $map['coinname'] = 'easy';
        $map['type'] = 1;
        $map['userid'] = $userid;

        $data = M('coinlist')->where($map)->find();

        //判断数据库里没有充值记录，则去区块中查询
        if (!$data) {

            //$userData['eth_address'] = '0x61cb9627e11689d491be1b883c33280c736f38e1';

            $url = "http://api.etherscan.io/api?module=account&action=tokentx&address=" . $userData['eth_address'] . "&startblock=0&endblock=999999999&sort=asc&apikey=H4R65KDWH86I2T8CD8R4ZU5TCXBAX8M7PR";

            $resUrl = requestGet($url);

            $res = json_decode($resUrl, true);
//dump($res);die;
            if ($res['status'] == 1 && !empty($res['result'])) {

                foreach ($res['result'] as $k => $v) {

//                    if($v['value'] / 1000000000000000000 > 0 && $v['to'] == strtolower($userData['eth_address']) && $v['contractAddress'] == '0xba1ed22c69ad00739ee2b4abd70e270be9e87ee2')
                    if ($v['value'] / 1000000000000000000 > 0 && $v['to'] == strtolower($userData['eth_address']) && $v['contractAddress'] == '0x6f18cf04504b3c517912efddaf1cc88745b5e87d') {

                        //交易数据入库
                        $info['userid'] = $userid;
//                        $info['phone'] = $userData['phone'];
                        $info['phone'] = $userData['phone']?$userData['phone']:$userData['username'];
                        $info['coinname'] = 'easy';
                        $info['address'] = $v['to'];
                        $info['hash'] = $v['hash'];
                        $info['amount'] = $v['value'] / 1000000000000000000;
                        $info['fee'] = 0;
                        $info['type'] = 1;
                        $info['addtime'] = $v['timeStamp'];
                        $info['endtime'] = time();
                        $info['status'] = 1;

                        //充值记录入库
                        M('coinlist')->add($info);

                        //账户中增加余额
                        M('user')->where(['id' => $userid])->setInc('z11', $v['value'] / 1000000000000000000);
                    }
                }
            }
        } else {

            //判断数据库里没有充值记录，则去区块中查询

            //$userData['eth_address'] = '0x61cb9627e11689d491be1b883c33280c736f38e1';

            $url = "http://api.etherscan.io/api?module=account&action=tokentx&address=" . $userData['eth_address'] . "&startblock=0&endblock=999999999&sort=asc&apikey=H4R65KDWH86I2T8CD8R4ZU5TCXBAX8M7PR";

            $resUrl = requestGet($url);

            $res = json_decode($resUrl, true);

            if ($res['status'] == 1 && !empty($res['result'])) {

                foreach ($res['result'] as $k => $v) {

//                    if($v['value'] / 1000000000000000000 > 0 && $v['to'] == strtolower($userData['eth_address']) && $v['contractAddress'] == '0xba1ed22c69ad00739ee2b4abd70e270be9e87ee2')
                    if ($v['value'] / 1000000000000000000 > 0 && $v['to'] == strtolower($userData['eth_address']) && $v['contractAddress'] == '0x6f18cf04504b3c517912efddaf1cc88745b5e87d') {

                        //再判断数据是否已经插入到数据库中
                        $isempty = M('coinlist')->where(['hash' => $v['hash']])->find();

                        if (!$isempty) {

                            //交易数据入库
                            $info['userid'] = $userid;
//                            $info['phone'] = $userData['phone'];
                            $info['phone'] = $userData['username'];
                            $info['coinname'] = 'easy';
                            $info['address'] = $v['to'];
                            $info['hash'] = $v['hash'];
                            $info['amount'] = $v['value'] / 1000000000000000000;
                            $info['fee'] = 0;
                            $info['type'] = 1;
                            $info['addtime'] = $v['timeStamp'];
                            $info['endtime'] = time();
                            $info['status'] = 1;

                            //充值记录入库
                            M('coinlist')->add($info);

                            //账户中增加余额
                            M('user')->where(['id' => $userid])->setInc('z11', $v['value'] / 1000000000000000000);
                        }
                    }
                }
            }
        }

    }


}